#ifndef SNIFFER_H
#define SNIFFER_H

#include <QObject>

// 内部 sniffer 基类
class YDSniffer : public QObject {
    Q_OBJECT
public:
    typedef QStringList job_t;

    explicit YDSniffer(QObject* parent = nullptr) : QObject(parent) {}
    virtual ~YDSniffer() {}

    virtual QString type() = 0;
    virtual void sniff(const job_t& job) = 0;

signals:
    void getUrl(const QString& url, const QString& realUrl);
    void error(const QString& url);

};

#include <QNetworkReply>

// 百度 sniffer
class YDBaiduDiskSniffer : public YDSniffer {
    Q_OBJECT
public:
    explicit YDBaiduDiskSniffer(QObject* parent = nullptr);
    virtual ~YDBaiduDiskSniffer();

    virtual QString type() {
        return "baidu";
    }

    virtual void sniff(const job_t& job);

private slots:
    void on_reply_error(QNetworkReply::NetworkError);
    void on_reply_finished();

private:
    // URL 字符串在传进程序之后，有可能会被改写，所以这里需要记录，不能用 reply 里面的 url 辨别
    typedef std::map<QNetworkReply*, QString> map_t;

    QString analyze(const QString& str);

    map_t map;
};

#endif // SNIFFER_H
